package vietnam.traveltools.adapter;

import java.util.List;

import vietnam.traveltools.variables.ListItem;
import vietnam.traveltools.view.AtmView;
import android.content.Context;
import android.database.DataSetObservable;
import android.database.DataSetObserver;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.SpinnerAdapter;

public class AtmAdapter extends ArrayAdapter<ListItem>  implements ListAdapter, SpinnerAdapter {
	private final DataSetObservable mDataSetObservable = new DataSetObservable();
   private List<ListItem>  _listItems;
   private Context         _context;
   public AtmAdapter(Context context, int textViewResourceId,List<ListItem> objects) {
       super(context, textViewResourceId, objects);
       this._context   = context;
       this._listItems = objects;
   }
   @Override
   public View getView(int position, View convertView, ViewGroup parent) {
       AtmView view = new AtmView(this._context);
       view.setListItem(this._listItems.get(position));
       return view;
   }
   public void notifyDataSetChanged() {
       mDataSetObservable.notifyChanged();
   }
   
   public boolean hasStableIds() {
       return false;
   }
   
   public void registerDataSetObserver(DataSetObserver observer) {
       mDataSetObservable.registerObserver(observer);
   }

   public void unregisterDataSetObserver(DataSetObserver observer) {
       mDataSetObservable.unregisterObserver(observer);
   }
   
   

   /**
    * Notifies the attached observers that the underlying data is no longer valid
    * or available. Once invoked this adapter is no longer valid and should
    * not report further data set changes.
    */
   public void notifyDataSetInvalidated() {
       mDataSetObservable.notifyInvalidated();
   }

   public boolean areAllItemsEnabled() {
       return true;
   }

   public boolean isEnabled(int position) {
       return true;
   }

   public View getDropDownView(int position, View convertView, ViewGroup parent) {
       return getView(position, convertView, parent);
   }

   public int getItemViewType(int position) {
       return 0;
   }

   public int getViewTypeCount() {
       return 1;
   }
   
   public boolean isEmpty() {
       return getCount() == 0;
   }
   
}
